using AC.Model;
using AC.Window.Helper;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AC.Window
{
    public partial class FrmMain : Form
    {
        public FrmMain()
        {
            InitializeComponent();
        }

        private void btn_Open_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                txt_Folder.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void btn_Run_Click(object sender, EventArgs e)
        {

            string rootPath = txt_Folder.Text + "/AutoCode_" + txt_DBName.Text;
            if (Directory.Exists(rootPath))
            {
                Directory.Delete(rootPath, true);
            }
            Directory.CreateDirectory(rootPath);
            string dalPath = rootPath + "/DAL";
            string managePath = rootPath + "/Manager";
            string bllPath = rootPath + "/BLL";
            string webPath = rootPath + "/Web";
            //1111
            Directory.CreateDirectory(dalPath);
            Directory.CreateDirectory(managePath);
            Directory.CreateDirectory(bllPath);
            Directory.CreateDirectory(webPath);
        } 

        private void btn_TestConn_Click(object sender, EventArgs e)
        {
            //string ip = Config.Read("IP");
            //Config.Write("text", ip);
        }

        private void FrmMian_Load(object sender, EventArgs e)
        {
            InitFromConfig();
        }

        private void InitFromConfig()
        {
            DBConnect connect = ConfigAccess.GetDBConnectInConfig();
            txt_IP.Text = connect.IP;
            txt_DBName.Text = connect.DBName;
            txt_LoginName.Text = connect.LoginName;
            txt_Password.Text = connect.Password;
            txt_Schema.Text = connect.SchemaName;
            txt_Folder.Text = connect.FolderPath;
        }
    }
}
